<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Fetch SNMP object subtree</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="snmp.setsecurity.html">SNMP::setSecurity</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.snmpexception.html">SNMPException</a></div>
 <div class="up"><a href="class.snmp.html">SNMP</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="snmp.walk" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SNMP::walk</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0)</p><p class="refpurpose"><span class="refname">SNMP::walk</span> &mdash; <span class="dc-title">Fetch <acronym title="Simple Network Management Protocol">SNMP</acronym> object subtree</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-snmp.walk-description">
  <h3 class="title">说明</h3>

  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>SNMP::walk</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$object_id</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$suffix_as_key</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$max_repetitions</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$non_repeaters</code></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   <span class="methodname"><strong>SNMP::walk()</strong></span> is used to read <acronym title="Simple Network Management Protocol">SNMP</acronym> subtree rooted at specified <em><code class="parameter">object_id</code></em>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-snmp.walk-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">object_id</code></em></dt>

    <dd>

     <p class="para">
      Root of subtree to be fetched
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">suffix_as_key</code></em></dt>

    <dd>

     <p class="para">
      By default full OID notation is used for keys in output array.
      If set to <strong><code>TRUE</code></strong> subtree prefix will be removed from keys leaving only suffix of object_id.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">non_repeaters</code></em></dt>

    <dd>

     <p class="para">
      This specifies the number of supplied variables that should not be iterated over.
      The default is to use this value from <acronym title="Simple Network Management Protocol">SNMP</acronym> object.
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">max_repetitions</code></em></dt>

    <dd>

     <p class="para">
       This specifies the maximum number of iterations over the repeating variables.
       The default is to use this value from <acronym title="Simple Network Management Protocol">SNMP</acronym> object.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-snmp.walk-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an associative array of the <acronym title="Simple Network Management Protocol">SNMP</acronym> object ids and their values on success or <strong><code>FALSE</code></strong> on error.
   When a <acronym title="Simple Network Management Protocol">SNMP</acronym> error occures <span class="methodname"><a href="snmp.geterrno.html" class="methodname">SNMP::getErrno()</a></span> and
   <span class="methodname"><a href="snmp.geterror.html" class="methodname">SNMP::getError()</a></span> can be used for retrieving error
   number (specific to SNMP extension, see class constants) and error message
   respectively.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-snmp.walk-errors">
<h3 class="title">错误／异常</h3>
<p class="para">
 本方法默认不抛出任何异常。如果要在某些库出错时抛出 SNMPException 
 异常，用户需要将 SNMP 类参数 <em><code class="parameter">exceptions_enabled</code></em> 
 设定为相应的值。更多细节见
 <a href="class.snmp.html#snmp.props.exceptions-enabled" class="link">
  <em><code class="parameter">SNMP::$exceptions_enabled</code></em> 的解释</a>。
</p>
</div>



 <div class="refsect1 examples" id="refsect1-snmp.walk-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="snmp.walk.example.basic">
   <p><strong>Example #1 <span class="methodname"><strong>SNMP::walk()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$session&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">(</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">::</span><span style="color: #0000BB">VERSION_1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"public"</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$fulltree&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">walk</span><span style="color: #007700">(</span><span style="color: #DD0000">"."</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$fulltree</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">close</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [SNMPv2-MIB::sysDescr.0] =&gt; STRING: Test server
    [SNMPv2-MIB::sysObjectID.0] =&gt; OID: NET-SNMP-MIB::netSnmpAgentOIDs.8
    [DISMAN-EVENT-MIB::sysUpTimeInstance] =&gt; Timeticks: (1150681750) 133 days, 4:20:17.50
    [SNMPv2-MIB::sysContact.0] =&gt; STRING: Nobody
    [SNMPv2-MIB::sysName.0] =&gt; STRING: server.localdomain
    ...
)
</pre></div>
   </div>
  </div>
  <div class="example" id="snmp.walk.example.suffix-as-key">
   <p><strong>Example #2 <em><code class="parameter">suffix_as_key</code></em> example</strong></p>
   <div class="example-contents"><p>
     <em><code class="parameter">suffix_as_key</code></em> may be used when merging multiple <acronym title="Simple Network Management Protocol">SNMP</acronym> subtrees into one.
     This example maps interface names to their type.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$session&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">(</span><span style="color: #0000BB">SNMP</span><span style="color: #007700">::</span><span style="color: #0000BB">VERSION_1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"public"</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">valueretrieval&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">SNMP_VALUE_PLAIN</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$ifDescr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">walk</span><span style="color: #007700">(</span><span style="color: #DD0000">".1.3.6.1.2.1.2.2.1.2"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">valueretrieval&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">SNMP_VALUE_LIBRARY</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$ifType&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">walk</span><span style="color: #007700">(</span><span style="color: #DD0000">".1.3.6.1.2.1.2.2.1.3"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$ifDescr</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$ifType</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />&nbsp;&nbsp;foreach(</span><span style="color: #0000BB">$ifDescr&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$n</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">[</span><span style="color: #0000BB">$n</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$ifType</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">];<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [1] =&gt; igb0
    [2] =&gt; igb1
    [3] =&gt; ipfw0
    [4] =&gt; lo0
    [5] =&gt; lagg0
)
Array
(
    [1] =&gt; INTEGER: ieee8023adLag(161)
    [2] =&gt; INTEGER: ieee8023adLag(161)
    [3] =&gt; INTEGER: ethernetCsmacd(6)
    [4] =&gt; INTEGER: softwareLoopback(24)
    [5] =&gt; INTEGER: ethernetCsmacd(6)
)
Array
(
    [igb0] =&gt; INTEGER: ieee8023adLag(161)
    [igb1] =&gt; INTEGER: ieee8023adLag(161)
    [ipfw0] =&gt; INTEGER: ethernetCsmacd(6)
    [lo0] =&gt; INTEGER: softwareLoopback(24)
    [lagg0] =&gt; INTEGER: ethernetCsmacd(6)
)
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-snmp.walk-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="snmp.geterrno.html" class="methodname" rel="rdfs-seeAlso">SNMP::getErrno()</a> - Get last error code</span></li>
   <li class="member"><span class="methodname"><a href="snmp.geterror.html" class="methodname" rel="rdfs-seeAlso">SNMP::getError()</a> - Get last error message</span></li>
  </ul>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="snmp.setsecurity.html">SNMP::setSecurity</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="class.snmpexception.html">SNMPException</a></div>
 <div class="up"><a href="class.snmp.html">SNMP</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
